<?php

namespace App\Services;

use Firebase\JWT\JWT;
use Firebase\JWT\Key;

class UserInfoJwt
{
    //加密
    public function jwtEn($data)
    {
        $key = 'sunqi';
        $payload = [
            'token' => $data,
            'iss' => 'http://example.org',
            'aud' => 'http://example.com',
            'iat' => 1356999524,
            'nbf' => 1357000000,
        ];
        $jwt = JWT::encode($payload, $key, 'HS256');

        return $jwt;
    }

    //解密
    public function jwtDe($data)
    {
        $key = 'sunqi';
        $decoded = JWT::decode($data, new Key($key, 'HS256'));
        $decoded_array = (array)$decoded;
        return $decoded_array;

    }
}